package com.luke.exercise.classloader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.log4j.helpers.Loader;

public class MonitorHotSwap implements Runnable {

    private String className = "com.luke.classloader.Hot";
    private Class hotClazz = null;
    private HotSwapURLClassLoader loader = null;
    
    public void run() {
        try {
           while(true) {
               
                initLoad();
                Object hot = hotClazz.newInstance();
                Method m = hotClazz.getMethod("hot");
                m.invoke(hot, null);
                Thread.sleep(10000);
            } 
        }catch (Exception e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
    }
    
    public void initLoad() throws ClassNotFoundException {
        loader = HotSwapURLClassLoader.getClassLoader();
        hotClazz = Loader.loadClass(className);
    }
    
}